﻿// This file is a script that can be executed with the F# Interactive.  
// It can be used to explore and test the library project.
// Note that script files will not be part of the project build.

open NumericalData
open NumericalData.Systems
//open NumericalData.Data
open System
open System.Collections
open System.Collections.Generic
open System.IO
open System.Diagnostics
open System.Reflection
open System.Diagnostics
open ExtensionMethods
open NumericalData.Statistics

//let b = new MethodsStatistics<Answer>(a,5)



//let rec getAnswer (sys:SLAE) (accur) (solvMeth:SLAE->double->Answer) = 
//    let watch = new Stopwatch()
//    watch.Start()
//    try
//        let ans = (solvMeth) sys accur
//        watch.Stop()
//        ans
//    with
//    |_ ->
//        watch.Stop()
//        new Answer(sys.ProducedBVector,sys.MaxIterations,watch.Elapsed,100.,accur)


//for j in 1..20 do
//    let accur = 0.001
//    let evm = MatrixGenerators<SquareMatrix>.GeneratePositiveDefinedMatrix j 10.
//    let vec = Vector.Generate j 10.
//    let sys = new SLAE(evm.Matrix,vec)
//    //let matr = evm.Matrix
//    //matr.Print()
//    //evm.EigenValuesVector.Print()
//    //let maxL = evm.EigenValuesVector.InnerArray |> Array.max
//    //let minL = evm.EigenValuesVector.InnerArray |> Array.min
//    //matr.Print()
//    //let matr = em.Matrix
//    
//
//    
//    //sys.InitialVectorIsZero <- false
//    let answ2 = sys.SolveUsingSimpleExplicitMethod accur
//    printfn "simple: iters %d precision %f" answ2.IterationsNumber answ2.Precision
//    let answ1 = sys.SolveUsingAdaptiveSimpleExplicitMethod accur (0.6,1.1)
//    printfn "adaptv: iters %d precision %f" answ1.IterationsNumber answ1.Precision
//    printfn "\n"
//for i in 0..10000 do
//    let accur = 0.0001
//    let matr = MatrixGenerators<SquareMatrix>.GenerateMatrixWithDiagonalDominance 10 10.
////    matr.Print()
//    let vec = Vector.Generate 10 10.
//    let sys = new SLAE(matr,vec)
//    sys.MaxIterations <- 10000
//    let answ = getAnswer sys accur SLAE.SolveUsingSimpleExplicitMethod
//    printfn "%d" answ.IterationsNumber
//printf "."
////let answ1 = sys.SolveUsingImplicitYakobiMethod accur
//printf "."
//let answ2 = sys.SolveUsingSimpleExplicitMethod accur


////Systems DB Generation
//let countOfSystems = 30
//let file = System.IO.File.Open(@"C:\net\MatrixMaterial.fs",FileMode.CreateNew)
//let fileWriter = new StreamWriter(file)
//
//for dim in 3..100 do 
//    let mutable count = 0
//    let mutable foundCount = 0
//    while foundCount < countOfSystems do
//        printfn "found %d" foundCount
//        let matrix = SquareMatrix.GenerateMatrixWithShuffledDiagonalDominance dim ( Double.Parse((count+1).ToString()) )
//        let initVec = Vector.Generate dim ( Double.Parse((count+1).ToString()) )
////        let sys = new SLAE(matrix,initVec)
////        sys.CalculateBMatrixAndBVectorWithYakobiMethod()
////        if sys.SystemIsSolvable then
////            let ans = sys.SolveUsingYakobiMethod(0.00001)
////            fileWriter.WriteLine ( "(\n" + sys.m_InitialMatrix.SPrint() + "," + sys.InitialVector.SPrint() + "\n)\n")
////            //fileWriter.WriteLine ("Answer vector:" + ans.AnswerVector.SPrint() + "\n")
////            foundCount <- foundCount + 1
//        fileWriter.WriteLine ( "(\n" + matrix.SPrint() + "," + initVec.SPrint() + "\n)\n")
//        //fileWriter.WriteLine ("Answer vector:" + ans.AnswerVector.SPrint() + "\n")
//        foundCount <- foundCount + 1
//        count <- count + 1
//    //fileWriter.WriteLine ( "-----------------------------------------------------------------------------------------")
//fileWriter.Close()
//file.Close()



//let mutable found = false
//let mutable ans:Answer = new Answer(new Vector(),0,new TimeSpan(),0.0)
//let mutable matrix = new Matrix()
//let mutable vector = new Vector()
//while found = false do
//    let matr = SquareMatrix.GenerateDiag 1000 3.
//    let vec = Vector.Generate 1000 3.
//    let sys = new SLAE(matr,vec)
//    sys.CalculateBMatrixAndBVectorWithYakobiMethod()
//    printfn "%A" sys.m_consumedTime.Milliseconds
//    if sys.SystemIsSolvable then
//        ans <- sys.SolveUsingYakobiMethod(0.1)
//        matrix <- matr
//        vector <- vec
//        found <- true




//let matr = 
//    new SquareMatrix(
//        [|
//           [|   38.135958;   -1.743345;   -0.268208;   -1.822267;   -1.365672;   0.606402;   0.314466;   1.655736;   2.171219;   1.089219;   1.019197;   -1.098198;   0.702489;|]
//           [|   -0.388931;   24.504407;   -1.523012;   -1.642690;   -0.710159;   -0.107985;   0.605762;   2.031562;   1.754709;   1.906361;   -1.309114;   2.172161;   1.253413;|]
//           [|   -0.175707;   1.462452;   46.114730;   -1.641362;   -2.253960;   -2.432219;   -1.376558;   2.250284;   -2.426939;   1.144267;   2.388446;   -1.064256;   -2.318570;|]
//           [|   1.104678;   -1.642185;   -2.355635;   23.660643;   -1.797045;   -1.545792;   1.911497;   -2.088995;   1.076583;   -0.896059;   1.497290;   0.390361;   -2.272021;|]
//           [|   -1.540933;   2.473481;   -1.871141;   1.371134;   15.053819;   -1.459095;   -1.494428;   -0.119086;   -1.717892;   1.352014;   -2.083859;   1.312581;   0.843179;|]
//           [|   0.951416;   -2.221639;   0.952205;   -0.461992;   0.932995;   11.651046;   1.921566;   -0.891589;   1.287336;   -0.252052;   1.887197;   -0.257648;   1.203406;|]
//           [|   -2.263321;   -2.239336;   0.842408;   1.247710;   -0.141489;   2.242305;   36.087596;   -2.481939;   1.608714;   -1.350039;   1.621425;   -1.298073;   -0.206026;|]
//           [|   1.347541;   -2.069828;   0.300515;   0.322570;   -0.494200;   2.228224;   0.699776;   28.177087;   0.002792;   1.633136;   -0.541201;   -0.961424;   0.670946;|]
//           [|   0.408748;   0.968795;   1.119568;   -0.328270;   0.225534;   -1.258339;   -0.871218;   0.146888;   7.954943;   -1.755092;   1.538506;   -0.465602;   -1.006497;|]
//           [|   -1.826164;   -1.655696;   0.825118;   1.842702;   1.628400;   1.830780;   -1.663919;   -1.360979;   -0.258999;   49.388130;   1.307895;   -1.535234;   -2.257853;|]
//           [|   2.158973;   1.542576;   -1.156370;   0.233887;   -1.372472;   -1.116391;   -0.290866;   1.687565;   -0.666443;   1.999482;   15.680413;   -0.563016;   0.924427;|]
//           [|   0.379764;   2.073145;   2.147086;   0.543315;   2.185264;   1.262009;   -1.711828;   -1.987703;   1.554388;   -0.144528;   1.534658;   38.581173;   -2.495264;|]
//           [|   0.128019;   -1.797505;   -0.468075;   -1.832253;   1.977400;   2.311673;   -1.293036;   -0.016613;   -0.917312;   0.086206;   -1.196742;   0.570339;   57.525942;|]
//        |])
//let vec = new Vector([| 0.625843; -1.743345; -0.268208; -1.822267; -1.365672; 0.606402; 0.314466; 1.655736; 2.171219; 1.089219; 1.019197; -1.098198; 0.702489; |])

//let matr = SquareMatrix.GenerateMatrixWithGiagonalDominance 100 10.
//let vec = Vector.Generate 100 10.
//let sys = new SLAE(matr,vec)
//let ans = sys.SolveUsingYakobiMethod(0.0001)




